<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>数据表征识别工具</title>
    <style>
        * {
            box-sizing: border-box;
            margin: 0;
            padding: 0;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }

        body {
            background: linear-gradient(135deg, #1a2a6c, #b21f1f, #fdbb2d);
            color: #333;
            line-height: 1.6;
            padding: 20px;
            min-height: 100vh;
        }

        .container {
            max-width: 1400px;
            margin: 0 auto;
            background-color: rgba(255, 255, 255, 0.95);
            border-radius: 12px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
            overflow: hidden;
        }

        header {
            background: linear-gradient(to right, #2c3e50, #4a6491);
            color: white;
            padding: 25px 40px;
            text-align: center;
        }

        h1 {
            font-size: 2.4rem;
            margin-bottom: 10px;
            letter-spacing: 1px;
        }

        .subtitle {
            font-size: 1.1rem;
            opacity: 0.9;
            max-width: 700px;
            margin: 0 auto;
        }

        .main-content {
            display: flex;
            padding: 30px;
            gap: 30px;
        }

        @media (max-width: 900px) {
            .main-content {
                flex-direction: column;
            }
        }

        .input-section, .output-section {
            flex: 1;
            background: white;
            border-radius: 10px;
            padding: 25px;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.08);
        }

        .section-title {
            font-size: 1.6rem;
            color: #2c3e50;
            margin-bottom: 20px;
            padding-bottom: 15px;
            border-bottom: 2px solid #3498db;
        }

        textarea {
            width: 100%;
            height: 300px;
            padding: 15px;
            border: 2px solid #ddd;
            border-radius: 8px;
            font-family: 'Consolas', 'Courier New', monospace;
            font-size: 15px;
            resize: vertical;
            transition: border-color 0.3s;
        }

        textarea:focus {
            outline: none;
            border-color: #3498db;
            box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.2);
        }

        .btn-container {
            display: flex;
            gap: 15px;
            margin-top: 20px;
        }

        button {
            flex: 1;
            padding: 14px 20px;
            background: linear-gradient(to right, #3498db, #2980b9);
            color: white;
            border: none;
            border-radius: 6px;
            font-size: 16px;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.3s ease;
        }

        button:hover {
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
        }

        button#clearBtn {
            background: linear-gradient(to right, #e74c3c, #c0392b);
        }

        .results-container {
            margin-top: 20px;
        }

        .results-grid {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 20px;
        }

        @media (max-width: 1200px) {
            .results-grid {
                grid-template-columns: 1fr;
            }
        }

        .field-table, .data-preview {
            background: #f8f9fa;
            border-radius: 8px;
            padding: 20px;
            overflow: hidden;
        }

        .data-preview {
            max-height: 400px;
            overflow-y: auto;
        }

        table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 10px;
        }

        th, td {
            padding: 12px 15px;
            text-align: left;
            border-bottom: 1px solid #e0e0e0;
        }

        th {
            background-color: #2c3e50;
            color: white;
            font-weight: 600;
        }

        tr:nth-child(even) {
            background-color: #f2f2f2;
        }

        tr:hover {
            background-color: #e3f2fd;
        }

        .field-type {
            font-weight: bold;
            color: #2980b9;
        }

        .json-container {
            background: #2c3e50;
            color: #f8f9fa;
            padding: 20px;
            border-radius: 8px;
            font-family: 'Consolas', 'Courier New', monospace;
            font-size: 14px;
            line-height: 1.5;
            max-height: 300px;
            overflow: auto;
        }

        .json-key {
            color: #3498db;
        }

        .json-value {
            color: #2ecc71;
        }

        .json-string {
            color: #f1c40f;
        }

        footer {
            text-align: center;
            padding: 25px;
            color: white;
            background: rgba(0, 0, 0, 0.2);
            font-size: 0.9rem;
        }

        .example-link {
            margin-top: 15px;
            color: #3498db;
            cursor: pointer;
            text-decoration: underline;
            display: inline-block;
        }
    </style>
</head>
<body>
<div class="container">
    <header>
        <h1>数据表征识别工具</h1>
        <p class="subtitle">粘贴您的结构化数据，自动识别字段名称、数据类型和数据结构</p>
    </header>

    <div class="main-content">
        <div class="input-section">
            <h2 class="section-title">输入数据</h2>
            <textarea id="dataInput" placeholder="在此粘贴您的结构化数据...">0.01000 stage=4 lon=118.314393 lat=25.037612 hei=8000.0 head=32.0 elev=-0.3 roll=0.0 vel=200.0 vx=106.1 vy=169.6 vz=-1.1 insX=0.0 insY=0.0 insZ=0.0
0.02000 stage=4 lon=118.314404 lat=25.037627 hei=8000.0 head=32.0 elev=-0.3 roll=0.0 vel=200.0 vx=106.1 vy=169.6 vz=-1.1 insX=0.0 insY=0.0 insZ=0.0
0.03000 stage=4 lon=118.314414 lat=25.037642 hei=8000.0 head=32.0 elev=-0.3 roll=0.0 vel=200.0 vx=106.1 vy=169.6 vz=-1.1 insX=0.0 insY=0.0 insZ=0.0
0.04000 stage=4 lon=118.314425 lat=25.037658 hei=8000.0 head=32.0 elev=-0.3 roll=0.0 vel=200.0 vx=106.1 vy=169.6 vz=-1.1 insX=0.0 insY=0.0 insZ=0.0</textarea>

            <div class="btn-container">
                <button id="analyzeBtn">分析数据</button>
                <button id="clearBtn">清除数据</button>
            </div>

            <p class="example-link" id="loadExample">加载示例数据</p>
        </div>

        <div class="output-section">
            <h2 class="section-title">识别结果</h2>
            <div class="results-container">
                <div class="results-grid">
                    <div class="field-table">
                        <h3>字段信息</h3>
                        <table id="fieldTable">
                            <thead>
                            <tr>
                                <th>字段名</th>
                                <th>数据类型</th>
                                <th>示例值</th>
                                <th>含义推测</th>
                            </tr>
                            </thead>
                            <tbody id="fieldTableBody">
                            <!-- 结果将通过JS填充 -->
                            </tbody>
                        </table>
                    </div>

                    <div class="data-preview">
                        <h3>数据预览</h3>
                        <div class="json-container" id="jsonPreview">
                            <!-- JSON预览将通过JS填充 -->
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <footer>
        <p>数据表征识别工具 &copy; 2023 | 自动解析结构化数据字段和类型</p>
    </footer>
</div>

<script>
    document.addEventListener('DOMContentLoaded', function () {
        const dataInput = document.getElementById('dataInput');
        const analyzeBtn = document.getElementById('analyzeBtn');
        const clearBtn = document.getElementById('clearBtn');
        const loadExample = document.getElementById('loadExample');
        const fieldTableBody = document.getElementById('fieldTableBody');
        const jsonPreview = document.getElementById('jsonPreview');

        // 示例数据
        const exampleData = `0.01000 stage=4 lon=118.314393 lat=25.037612 hei=8000.0 head=32.0 elev=-0.3 roll=0.0 vel=200.0 vx=106.1 vy=169.6 vz=-1.1 insX=0.0 insY=0.0 insZ=0.0
0.02000 stage=4 lon=118.314404 lat=25.037627 hei=8000.0 head=32.0 elev=-0.3 roll=0.0 vel=200.0 vx=106.1 vy=169.6 vz=-1.1 insX=0.0 insY=0.0 insZ=0.0
0.03000 stage=4 lon=118.314414 lat=25.037642 hei=8000.0 head=32.0 elev=-0.3 roll=0.0 vel=200.0 vx=106.1 vy=169.6 vz=-1.1 insX=0.0 insY=0.0 insZ=0.0
0.04000 stage=4 lon=118.314425 lat=25.037658 hei=8000.0 head=32.0 elev=-0.3 roll=0.0 vel=200.0 vx=106.1 vy=169.6 vz=-1.1 insX=0.0 insY=0.0 insZ=0.0`;

        // 字段含义映射
        const fieldMeanings = {
            'timestamp': '时间戳（单位：秒）',
            'stage': '状态阶段',
            'lon': '经度',
            'lat': '纬度',
            'hei': '高度（单位：米）',
            'head': '航向角（单位：度）',
            'elev': '俯仰角（单位：度）',
            'roll': '滚转角（单位：度）',
            'vel': '速度标量（单位：m/s）',
            'vx': 'X轴速度分量',
            'vy': 'Y轴速度分量',
            'vz': 'Z轴速度分量',
            'insX': '惯性导航X轴偏移',
            'insY': '惯性导航Y轴偏移',
            'insZ': '惯性导航Z轴偏移'
        };

        // 加载示例数据
        loadExample.addEventListener('click', function () {
            dataInput.value = exampleData;
            analyzeData();
        });

        // 分析数据
        analyzeBtn.addEventListener('click', analyzeData);

        // 清除数据
        clearBtn.addEventListener('click', function () {
            dataInput.value = '';
            fieldTableBody.innerHTML = '';
            jsonPreview.innerHTML = '';
        });

        function analyzeData() {
            const data = dataInput.value.trim();
            if (!data) {
                alert('请输入数据进行分析');
                return;
            }

            const lines = data.split('\n');
            if (lines.length === 0) return;

            // 解析第一行获取字段信息
            const firstLine = lines[0].trim();
            const parts = firstLine.split(' ');

            // 识别字段
            const fields = [];

            // 第一个字段是时间戳（无等号）
            fields.push({
                name: 'timestamp',
                value: parts[0],
                type: 'float'
            });

            // 解析其余键值对字段
            for (let i = 1; i < parts.length; i++) {
                const [key, value] = parts[i].split('=');
                const numValue = parseFloat(value);

                fields.push({
                    name: key,
                    value: value,
                    type: isNaN(numValue) ? 'string' :
                        value.includes('.') ? 'float' : 'int'
                });
            }

            // 清空表格
            fieldTableBody.innerHTML = '';

            // 填充字段表格
            fields.forEach(field => {
                const row = document.createElement('tr');

                row.innerHTML = `
                        <td>${field.name}</td>
                        <td><span class="field-type">${field.type}</span></td>
                        <td>${field.value}</td>
                        <td>${fieldMeanings[field.name] || '未知字段'}</td>
                    `;

                fieldTableBody.appendChild(row);
            });

            // 生成数据预览（第一行）
            const firstLineObj = {};
            fields.forEach(field => {
                firstLineObj[field.name] = field.type === 'float' || field.type === 'int' ?
                    parseFloat(field.value) : field.value;
            });

            // 美化JSON显示
            jsonPreview.innerHTML = syntaxHighlight(JSON.stringify(firstLineObj, null, 2));
        }

        // JSON语法高亮函数
        function syntaxHighlight(json) {
            if (!json) return '';

            json = json.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
            return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) {
                let cls = 'json-value';
                if (/^"/.test(match)) {
                    if (/:$/.test(match)) {
                        cls = 'json-key';
                    } else {
                        cls = 'json-string';
                    }
                } else if (/true|false/.test(match)) {
                    cls = 'json-boolean';
                } else if (/null/.test(match)) {
                    cls = 'json-null';
                }
                return '<span class="' + cls + '">' + match + '</span>';
            });
        }

        // 初始分析示例数据
        analyzeData();
    });
</script>
</body>
</html>